package com.ruoyi.common.core.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LicensePlateValidator {



        // 定义传统车牌号码的正则表达式
        private static final String TRADITIONAL_LICENSE_PLATE_PATTERN = "^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z0-9]{5}$";
        // 定义新能源车牌号码的正则表达式
        private static final String NEW_ENERGY_LICENSE_PLATE_PATTERN = "^[\u4e00-\u9fa5]{1}[A-Z]{1}[DF]{1}[A-Z0-9]{5}$";

        // 编译正则表达式
        private static final Pattern traditionalPattern = Pattern.compile(TRADITIONAL_LICENSE_PLATE_PATTERN);
        private static final Pattern newEnergyPattern = Pattern.compile(NEW_ENERGY_LICENSE_PLATE_PATTERN);

        public static boolean isValidLicensePlate(String licensePlate) {
            if (licensePlate == null) {
                return false;
            }
            // 匹配传统车牌号码
            Matcher traditionalMatcher = traditionalPattern.matcher(licensePlate);
            if (traditionalMatcher.matches()) {
                return true;
            }
            // 匹配新能源车牌号码
            Matcher newEnergyMatcher = newEnergyPattern.matcher(licensePlate);
            return newEnergyMatcher.matches();
        }

        public static void main(String[] args) {
            // 测试用例
            String[] testPlates = {"冀DW6784", "沪B67890", "粤DF1234", "川FZ5678", "京A1B2C3", "浙A123456"};

            for (String plate : testPlates) {
                System.out.println("车牌号码: " + plate + " 是否有效: " + isValidLicensePlate(plate));
            }
        }
    }
